﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PES_TurnierManager.Model
{
    public class HumanPlayer : IComparable<HumanPlayer>
    {
        private string mName;
        private string mTeamName;
        private PlayerStatistics mCurrentTournamentStatistics;

        public HumanPlayer(string name)
        {
            mName = name;
            mCurrentTournamentStatistics = new PlayerStatistics();
        }

        public void setTeamName(string teamName)
        {
            mTeamName = teamName;
        }

        public string getPlayerName()
        {
            return mName;
        }

        public string getTeamName()
        {
            return mTeamName;
        }

        public void addDataOfMatch(uint goalsMarked, uint goalsGot)
        {
            mCurrentTournamentStatistics.addDataOfMatch(goalsMarked, goalsGot);
        }

        public uint getPoints()
        {
            return mCurrentTournamentStatistics.getPoints();
        }

        public uint getGamesWon()
        {
            return mCurrentTournamentStatistics.getGamesWon();
        }

        public uint getGamesLost()
        {
            return mCurrentTournamentStatistics.getGamesLost();
        }

        public int getGoalDifference()
        {
            return mCurrentTournamentStatistics.getGoalDifference();
        }

        public uint getMinusGoals()
        {
            return mCurrentTournamentStatistics.getMinusGoals();
        }

        public uint getPlusGoals()
        {
            return mCurrentTournamentStatistics.getPlusGoals();
        }

        public uint getGamesPlayed()
        {
            return mCurrentTournamentStatistics.getGamesPlayed();
        }

        public PlayerStatistics getStats()
        {
            return mCurrentTournamentStatistics;
        }

        /// <summary>
        /// Compares the stats of the player with another, the result
        /// is in descending order
        /// </summary>
        /// <param name="otherPlayer">player to compare against</param>
        /// <returns></returns>
        public int CompareTo(HumanPlayer otherPlayer)
        {
            if (otherPlayer.getPoints() > getPoints())
                return 1;
            else if (getPoints() > otherPlayer.getPoints())
                return -1;

            //Points are equal. Compare the goals marked.
            if (otherPlayer.getPlusGoals() > getPlusGoals())
                return 1;
            else if (getPlusGoals() > otherPlayer.getPlusGoals())
                return -1;

            //Plus goals are equal. Compare the goaldifference
            if (otherPlayer.getGoalDifference() > getGoalDifference())
                return 1;
            else if (getGoalDifference() > otherPlayer.getGoalDifference())
                return -1;

            return 0;
        }
    }
}
